package com.zhsj.OkeHomeConsumption.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.utils.BasePagerAdapter;
import com.zhsj.OkeHomeConsumption.utils.MultiTouchViewPager;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import me.relex.circleindicator.CircleIndicator;

/**
 *    author : Xingdx
 *
 *    time   : 2019/03/05
 *    desc   : 查看大图
 */
public final class PhotoActivity extends Activity {
    private static String POS = "pos";
    private static String LISTDATA = "listdata";
    private static String TAG = "tag";
    private CircleIndicator indicator;
    private MultiTouchViewPager viewPager;
    private int pos;
    private List<String> mPhotoPath = new ArrayList<>();
    private LayoutInflater mInflater;
    private String  tag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        findViews(savedInstanceState);
        init();
    }
    protected void init() {
        viewPager.setAdapter(new DraweePagerAdapter());
        indicator.setViewPager(viewPager);
        viewPager.setCurrentItem(pos);
        viewPager.setAdapter(new DraweePagerAdapter());
        indicator.setViewPager(viewPager);
        viewPager.setCurrentItem(pos);
    }
    // 网图拍摄 固定高度300
    public static Intent createCircleIntent(Activity context, List<String> Datas, int position, String tag) {
        Intent intent = new Intent(context, PhotoActivity.class );
        intent.putExtra(POS, position);
        intent.putExtra(LISTDATA, (Serializable) Datas);
        intent.putExtra(TAG,tag);
        return intent;
    }
    public static Intent createCircleIntent(Context context, List<String> Datas, int position) {
        Intent intent = new Intent(context, PhotoActivity.class);
        intent.putExtra(POS, position);
        intent.putExtra(LISTDATA, (Serializable) Datas);
        return intent;
    }
    protected void findViews(Bundle savedInstanceState) {
        ((ImageView) findViewById(R.id.toolbar)).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onBackPressed();
                    }
                });
        indicator = (CircleIndicator) findViewById(R.id.indicator);
        viewPager = (MultiTouchViewPager) findViewById(R.id.view_pager);
        pos = getIntent().getExtras().getInt(POS);
        mPhotoPath = (List<String>) getIntent().getSerializableExtra(LISTDATA);
        tag = (String) getIntent().getStringExtra(TAG);
    }

    public class DraweePagerAdapter extends BasePagerAdapter {

        @Override
        public int getCount() {
            return mPhotoPath.size();
        }

        @Override
        public View getItemView(ViewGroup container, int position) {
            RelativeLayout view =(RelativeLayout) LayoutInflater.from(PhotoActivity.this).inflate(R.layout.item_photoviewpager, null);
            ImageView iv_fixed = (ImageView)view.findViewById(R.id.iv_fixed);
            ImageView iv_max = (ImageView)view.findViewById(R.id.iv_max);
            if (TextUtils.isEmpty(tag)){
                iv_fixed.setVisibility(View.GONE);
                iv_max.setVisibility(View.VISIBLE);
                Glide.with(PhotoActivity.this)
                        .load(mPhotoPath.get(position))
                        .into(iv_max);
            }else{
                iv_fixed.setVisibility(View.VISIBLE);
                iv_max.setVisibility(View.GONE);
                Glide.with(PhotoActivity.this)
                        .load(mPhotoPath.get(position))
                        .into(iv_fixed);
            }
            return view;
        }

    }

}